<template>
    <div>
        <h1>新增居民</h1>
        <tbody class="table">
        <tbody>
            <tr>
                <td>姓名</td>
                <td>
                    <input type="text" v-model="data.Zname">
                </td>
            </tr>
            <tr>
                <td>手机号</td>
                <td>
                    <input type="text" v-model="data.Phone">
                </td>
            </tr>
            <tr>
                <td>身份证号</td>
                <td>
                    <input type="text" v-model="data.SFZH">
                </td>
            </tr>
            <tr>
                <td>管理小区</td>
                <td>
                    <input type="text" v-model="data.GLXQ">
                </td>
            </tr>
            <tr>
                <td>Tid</td>
                <td>
                    <select v-model="data.Tid">
                        <option value="0">选择类型</option>
                        <option v-for="d in Bang" :value="d.Tid">{{ d.Tname }}</option>
                    </select>

                </td>
            </tr>
             <tr>
                <td>性别</td>
                <td>
                    <input v-model="data.Set" type="radio" name="Set" value="false">男
                    <input v-model="data.Set" type="radio" name="Set" value="true">女
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="button" class="btn btn-success" value="新增" @click="saveinfo">
                    <a href="/">返回</a>
                </td>
            </tr>
        </tbody>
        </tbody>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import { ref,onMounted} from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
onMounted(()=>{
    bang();
})
const bang=()=>{
    axios.get("/api/Foum/ZYBang").then(res=>{
        Bang.value=res.data
    })

}
const Bang=ref([{
    "Tid": 0,
    "Tname": "string"
}])
const data = ref({
  "Zid": 0,
  "Zname": "",
  "Phone": "",
  "SFZH": "",
  "Tid": 0,
  "GLXQ": "",
  "Set": true
})
const saveinfo = () => {
    if(data.value.GLXQ=="")
{
    alert("管理小区不能为空");
    return;
    
}
if(data.value.Phone=="")
{
    alert("手机号不能为空");
    return;
    
}
 let zz=/^1[3-9]\d{9}$/;
    if(!zz.test(data.value.Phone))
    {
       alert("手机格式不对")
       return;
    }
    if(data.value.SFZH=="")
{
    alert("身份证号不能为空");
    return;
    
}
     let FF=/^1[3-9]\d{9}$/;
    if(!FF.test(data.value.SFZH))
    {
       alert("身份证号不能小于大于18位数")
       return;
    }

if(data.value.Zname=="")
{
    alert("姓名不能为空");
    return;
    
}
if(data.value.Tid==0)
{
    alert("类型不能为空");
    return;
    
}
    axios.post('/api/Foum/AddZy', data.value).then(res => {
        if (res.data > 0) {
            alert("新增成功")
            router.push("/zyshow");
        }
        else {
            alert("新增失败...")
        }
    })
}
</script>

<style scoped></style>